/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.sc.senai.model.util;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

/**
 * Hibernate Utility class with a convenient method to get Session Factory object.
 *
 * @author jefferson_augusto
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();
    
    private static SessionFactory buildSessionFactory(){
        try{
            AnnotationConfiguration arquivoConfiguracao = new AnnotationConfiguration();
            arquivoConfiguracao.configure("hibernate.cfg.xml");
            return arquivoConfiguracao.buildSessionFactory();
        } catch (Throwable ex) {
            System.out.printf("Criação do SessionFactory falhou: %s\n", ex);
            throw new ExceptionInInitializerError();
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
